package com.jt.config;

import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Configuration //标识我是一个配置类  相当于application.xml
                //设定包扫描路径
@ComponentScan("com.jt")//如果注解中只有value属性  则可以省略
//@PropertySource  作用：加载指定的pro配置文件  将数据保存到Spring容器中
@PropertySource(value = "classpath:/user.properties",encoding = "utf-8")
public class SpringConfig {
    //定义对象属性  准备接受数据
    //@Value("${user.id}")在Spring容器中查找key=user.id的数据，通过${}
    @Value("${user.id}")
    private Integer id;
    @Value("${user.username}")
    private String username;
    @Bean
    public User user(){

        User user = new User();
        user.setId(id);
        user.setUsername(username);
        return user;
    }

}
